﻿$(document).ready(function () {

    var interval = 2000;   //number of mili seconds between each call
    var refresh = function () {
        $.ajax({
            url: "AjaxSelfService.aspx",

            data: {
                Action: $("#Action").val()
            },

            cache: false,

            success: function (contents) {
                //alert(html);

                if (contents == "@reload") {
                    location.reload();
                    return;
                }

                if (contents.length > 10) {
                    CanContinue = 1;
                    var ctrl = contents.substring(0, 1);

                    $("#maincontent").html(contents.substring(1));

                    if (ctrl == "1") { 
                        $(".swiper-container").animate({
                            opacity: '1',
                            right: '50%',
                        }, 500);
                    }
                    
                }


                setTimeout(function () {
                    refresh();
                }, interval);


            },

            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //alert(XMLHttpRequest.status);
                //alert(XMLHttpRequest.readyState);
                //alert(textStatus);

                setTimeout(function () {
                    refresh();
                }, interval);
            }

        });


    };


    //make it global access
    window.updateErrorMessage = function (msg) {
        $('#error').html(msg).hide().fadeIn(500);
    }

    refresh();

});